﻿using OpenIddict.Abstractions;
using OpenIddict.Server;
using WT.OpenIddict.Domain;

namespace WT.OpenIddict.WebApi.OpenIddictGrantTypeExtension;

public static class OpenIddictCustomExtension
{
    /// <summary>
    ///     判断是不是微信扫码登陆
    /// </summary>
    /// <param name="request"></param>
    /// <returns></returns>
    /// <exception cref="ArgumentNullException"></exception>
    public static bool IsWxLoginGrantType(this OpenIddictRequest request)
    {
        if (request == null) throw new ArgumentNullException("request");

        return string.Equals(request.GrantType, OpenIddictConst.WxGrantType, StringComparison.Ordinal);
    }


    public static OpenIddictServerBuilder AddCustomGrantType(this OpenIddictServerBuilder builder, string grantType)
    {
        return builder.Configure(delegate(OpenIddictServerOptions options) { options.GrantTypes.Add(grantType); });
    }
}